Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

overlord/snapstate: add migration function to fix invalid channel spec #7364

Closed

Conversation

anonymouse64
Copy link
Member

Note, I wasn't able to finish the following things that perhaps should be done before merging this, so feel free to take over this branch and clean up as necessary while I'm offline:

  • Add a spread test for this
  • Add a unit test for tracks upgraded as well (i.e. /edinburgh -> edinburgh)

This is the second part of the fix for https://bugs.launchpad.net/snapd/+bug/1841475

Previously, snapd performed no validation of the channel spec on refresh and install and just passed the string to the store for validation, however now we have to handle model constraints amongst other things and so we check the channel spec on refresh/update. This is problematic for clients that may have installed snaps using an unsupported channel spec with a leading "/" as in "/" which either implied "latest/" or as in "/" which implied just "".

This patch fixes the problem "on the fly" when we encounter such a channel spec in case it exists in some deployments and corrects it by removing the leading "/" in order to keep the same expected behavior such that "/stable" gets changed to "stable" which has a defined semantic around it.

Notably, we do this before calling resolveChannel, because we don't want to have that function grow too complicated so it can be more generally useful and instead just patch the snap state before that function gets called so it "just works" by the time we get there.

The migration function also returns the new channel so that the in memory snapst can be updated to match what's now in the state so there are no inconsistencies later on, otherwise we will get change conflicts.

Previously, snapd performed no validation of the channel spec on refresh
and install and just passed the string to the store for validation,
however now we have to handle model constraints amongst other things and
so we check the channel spec on refresh/update. This is problematic for
clients that may have installed snaps using an unsupported channel spec
with a leading "/" as in "/<risk>" which either implied "latest/<risk>"
or as in "/<track>" which implied just "<track>".

This patch fixes the problem "on the fly" when we encounter such a
channel spec in case it exists in some deployments and corrects it by
removing the leading "/" in order to keep the same expected behavior
such that "/stable" gets changed to "stable" which has a defined
semantic around it.

Notably, we do this before calling resolveChannel, because we don't want
to have that function grow too complicated so it can be more generally
useful and instead just patch the snap state before that function gets
called so it "just works" by the time we get there.

The migration function also returns the new channel so that the in 
memory snapst can be updated to match what's now in the state so there
are no inconsistencies later on, otherwise we will get change conflicts.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
This test ensures that old branch specs are automatically upgraded to
the current supported spec.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
@mvo5 mvo5 added this to the 2.41 milestone Aug 28, 2019
@pedronis
Copy link
Collaborator

@chipaca is looking at a more holistic approach to this and also providing warnings

@pedronis
Copy link
Collaborator

we are working on a lower level patch and also all other related code has been reverted for now

@pedronis pedronis closed this Aug 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants